<script lang="ts">
import { defineComponent } from 'vue';

export default defineComponent({
  name: 'App',
  onLaunch() {
    console.log('App Launch')
  },
  onShow() {
    console.log('App Show')
  },
  onHide() {
    console.log('App Hide')
  },
  onBackPress(event: any, fromPage: any) {
    // #ifdef APP-ANDROID || APP-HARMONY
    let firstBackTime = 0;

    if (firstBackTime === 0) {
      uni.showToast({
        title: '再按一次退出应用',
        position: 'bottom',
      });
      firstBackTime = Date.now();
      setTimeout(() => {
        firstBackTime = 0;
      }, 2000);
      return true;
    } else if (Date.now() - firstBackTime < 2000) {
      firstBackTime = Date.now();
      plus.runtime.quit();
      return true;
    }
    return true;
    // #endif
  },
  onExit() {
    console.log('App Exit');
  },
});
</script>